/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 小峰
 * Date: 2019-10-24
 * Time: 9:15
 */
public class Main {

    public static void main(String[] arg) {
        fengTest01();
        //System.out.println(mathematics(3));
        //System.out.println(fibonacci(80));
    }

    public static void fengTest01() {
        ArrayList<Integer> intArray = new ArrayList<>();
        for (int i = 0; i < 1000; i += 10) {
            intArray.add(i);
        }
        intArray.add(2,22);
        System.out.println("contains 40" + intArray.contains(40));
        System.out.println(intArray.remove(3));
        System.out.println(intArray.size());
        System.out.println(intArray.indexOf(40));
        System.out.println(intArray);
    }

    /**
     * 计算 1+2+3+4+5+....N 的结果
     *
     * @param n
     * @return
     */
    public static int mathematics(int n) {
        return (n + 1) * n / 2;
    }

    /**
     * 斐波那契数列  0,1,1,2,3,5,8 ....N
     * 前两个数的和是第三个数, 求第 n 个数是多少
     *
     * @param n
     * @return
     */
    public static long fibonacci(int n) {

        if (n <= 1) {
            return n;
        }
        long first = 0, second = 1, sum;
        StringBuilder strBuilder = new StringBuilder();
        strBuilder.append(first).append(",").append(second).append(",");

        for (int i = 0; i <= n - 1; i++) {
            sum = first + second;
            first = second;
            second = sum;
            strBuilder.append(second).append(",");
        }
        System.out.println(strBuilder.toString());
        return second;



    }
}
